//
//  Test1ViewController.m
//  JKNSURLSession
//
//  Created by 王冲 on 2019/1/22.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import "Test1ViewController.h"

@interface Test1ViewController ()

@end

@implementation Test1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    JKLog(@"哈哈");
    // 1.创建url:http://localhost
    NSURL *url = [NSURL URLWithString:@"http://localhost/test.json"];
    [self taskWithUrl:url];
}

-(void)taskWithUrl:(NSURL *)url{
    
    [[[NSURLSession sharedSession]dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        // 反序列化
        id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        
        NSLog(@"%@",result);
    }] resume];
}

@end
